package cn.org.atool.generator.demo.dm;

import java.lang.Boolean;
import java.lang.String;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.test4j.module.ICore.DataMap;
import org.test4j.module.database.IDatabase;
import org.test4j.module.database.annotations.ColumnDef;
import org.test4j.module.database.annotations.ScriptTable;
import org.test4j.tools.datagen.IDataMap;
import org.test4j.tools.datagen.KeyValue;

/**
 * MyAddressDataMap: 表(实体)数据对比(插入)构造器
 *
 * @author Powered By Test4J
 */
@ScriptTable("address")
public class MyAddressDataMap extends DataMap<MyAddressDataMap> {
  private boolean isTable;

  private Supplier<Boolean> supplier = () -> this.isTable;

  @ColumnDef(
      value = "id",
      type = "bigint(21) unsigned",
      primary = true,
      autoIncrease = true
  )
  public final transient KeyValue<MyAddressDataMap> id = new KeyValue(this, "id", "id", supplier);

  @ColumnDef(
      value = "address",
      type = "varchar(45)"
  )
  public final transient KeyValue<MyAddressDataMap> address = new KeyValue(this, "address", "address", supplier);

  @ColumnDef(
      value = "gmt_created",
      type = "datetime"
  )
  public final transient KeyValue<MyAddressDataMap> gmtCreated = new KeyValue(this, "gmt_created", "gmtCreated", supplier);

  @ColumnDef(
      value = "gmt_modified",
      type = "datetime"
  )
  public final transient KeyValue<MyAddressDataMap> gmtModified = new KeyValue(this, "gmt_modified", "gmtModified", supplier);

  @ColumnDef(
      value = "is_deleted",
      type = "tinyint(2)"
  )
  public final transient KeyValue<MyAddressDataMap> isDeleted = new KeyValue(this, "is_deleted", "isDeleted", supplier);

  @ColumnDef(
      value = "user_id",
      type = "bigint(20)"
  )
  public final transient KeyValue<MyAddressDataMap> userId = new KeyValue(this, "user_id", "userId", supplier);

  MyAddressDataMap(boolean isTable) {
    super();
    this.isTable = isTable;
  }

  MyAddressDataMap(boolean isTable, int size) {
    super(size);
    this.isTable = isTable;
  }

  /**
   * 创建MyAddressDataMap
   * 初始化主键和gmtCreate, gmtModified, isDeleted等特殊值
   */
  public MyAddressDataMap init() {
    this.id.autoIncrease();
    return this;
  }

  public MyAddressDataMap with(Consumer<MyAddressDataMap> init) {
    init.accept(this);
    return this;
  }

  public static MyAddressDataMap table() {
    return new MyAddressDataMap(true, 1);
  }

  public static MyAddressDataMap table(int size) {
    return new MyAddressDataMap(true, size);
  }

  public static MyAddressDataMap entity() {
    return new MyAddressDataMap(false, 1);
  }

  public static MyAddressDataMap entity(int size) {
    return new MyAddressDataMap(false, size);
  }

  /**
   * DataMap数据和表[address]数据比较
   */
  public MyAddressDataMap eqTable() {
    IDatabase.db.table("address").query().eqDataMap(this);
    return this;
  }

  /**
   * DataMap数据和表[address]数据比较
   */
  public MyAddressDataMap eqQuery(String query) {
    IDatabase.db.table("address").queryWhere(query).eqDataMap(this);
    return this;
  }

  /**
   * DataMap数据和表[address]数据比较
   */
  public MyAddressDataMap eqQuery(IDataMap query) {
    IDatabase.db.table("address").queryWhere(query).eqDataMap(this);
    return this;
  }

  /**
   * 清空[address]表数据
   */
  public MyAddressDataMap clean() {
    IDatabase.db.cleanTable("address");
    return this;
  }

  /**
   * 插入[address]表数据
   */
  public MyAddressDataMap insert() {
    IDatabase.db.table("address").insert(this);
    return this;
  }

  /**
   * 先清空, 再插入[address]表数据
   */
  public MyAddressDataMap cleanAndInsert() {
    return this.clean().insert();
  }

  public static class Factory {
    public MyAddressDataMap table() {
      return MyAddressDataMap.table();
    }

    public MyAddressDataMap table(int size) {
      return  MyAddressDataMap.table(size);
    }

    public MyAddressDataMap initTable() {
      return MyAddressDataMap.table().init();
    }

    public MyAddressDataMap initTable(int size) {
      return  MyAddressDataMap.table(size).init();
    }

    public MyAddressDataMap entity() {
      return MyAddressDataMap.entity();
    }

    public MyAddressDataMap entity(int size) {
      return  MyAddressDataMap.entity(size);
    }
  }
}
